import allure
import pytest
import requests
from common.base_request import BaseRequest
from common.yaml_opt import YamlTools
version='1.2.1'
sess = requests.session()

logindata=YamlTools.read_yaml_file('login.yaml')[0]
getdata=YamlTools.read_yaml_file('getdata.yaml')[0]
# print(logindata)
@allure.epic(logindata['request']['epic'])
@allure.epic(logindata['request']['feature'])
@allure.epic(logindata['request']['story'])
@pytest.mark.skipif(version=='1.2.2',reason='不想执行')
@pytest.mark.api
@pytest.mark.parametrize('mylogindata',logindata['parametrize'])
def testlogin001(mylogindata):
    # print(mylogindata)
    data=mylogindata['data']
    res=BaseRequest.execute_api_request(request=logindata['request'],parametrize=mylogindata)
    # res = sess.request("post", url="http://192.168.1.111:8080/pinter/bank/api/login", data=data)
    print(res.json())
    # assert res.json()['message']=='success'
    assert res.json()['message']==mylogindata['expect']['msg']

@allure.epic(logindata['request']['epic'])
@allure.epic(logindata['request']['feature'])
@allure.epic(logindata['request']['story'])
@pytest.mark.skipif(version=='1.2.2',reason='不想执行')
@pytest.mark.api
@pytest.mark.parametrize('mygetdata',getdata['parametrize'])
def testget(mygetdata):
    # data=mygetdata['data']
    res=BaseRequest.execute_api_request(request=getdata['request'],parametrize=mygetdata)
    # res = sess.request("post", url="http://192.168.1.111:8080/pinter/bank/api/login", data=data)
    print(res.json())
    # assert res.json()['message']=='success'
    assert res.json()['code']==mygetdata['expect']['code']

    
